package org.openlaszlo.eu.dto;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.Annotations;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * This abstract class provide common functionality for DTOs.
 * @author Dominique Vernier
 * 
 */
public abstract class DTO {

	/**
	 * This method serialize an object via XStream.
	 * The object can be annotated.
	 * It request the implementation of an abstract method which specified the annotated class.
	 * i.e.<br>
	 * <code>	protected void setAnnotations(XStream xstream) {<br>
		Annotations.configureAliases(xstream, ErrorMessageDTO.class);<br>
		}<br>
		</code>
	 * @return an XML string
	 */
	public String toXML() {
		XStream xstream = new XStream(new DomDriver());
		setAnnotations(xstream);
		return xstream.toXML(this);
	}
	
	/**
	 * Have to be implemented by a subclass.
	 * @param xstream
	 */
	protected abstract void setAnnotations(XStream xstream);
}
